<?php

use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\GoodsBrowse;



class GoodsBrowseTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $users = User::query()->with('goods','shop')->get();



        foreach ($users as $k=>$v) {
            foreach ($v->goods as $gv) {
                $GoodsBrowse = factory(GoodsBrowse::class)->times($v->shop->count())
                    ->make()->each(function($query , $index) use ($v , $gv){
                        $query->user_id     = $v->id;
                        $query->goods_id    = $gv->id;
                        $query->shop_id     = $v->shop[$index]->id;
                        $query->pagevies    = 0; // 浏览量
                        $query->order_num   = 0; // 订单量
                        $query->deal_num    = 0; // 成交量
                        $query->show_num    = 0; // 展现量
                    });
                GoodsBrowse::insert($GoodsBrowse->toArray());
            }
        }

        //
    }
}
